How to find all tables in Oracle that have specific columns?
How to find all tables in Oracle that have specific columns?
550
17-Jul-2023
Updated on 18-Jul-2023
Aryan Kumar
18-Jul-2023To find all tables in Oracle that have specific columns, you can use the following SQL query:
SQL
This query will first select all tables from the
all_tablesview. Theall_tablesview is a data dictionary view that contains information about all of the tables in the database.The next part of the query uses the
EXISTSclause to check if each table in theall_tablesview has the specified columns. TheEXISTSclause takes a subquery as its argument. The subquery in this case selects all columns from theall_tab_colsview where the table name is equal to the table name in theall_tablesview and the column name is equal to one of the specified columns.If the subquery returns any rows, then the
EXISTSclause will returnTRUE. This means that the table in theall_tablesview has the specified columns.The final part of the query selects the
table_namecolumn from theall_tablesview for all tables that have the specified columns.To run this query, you will need to connect to the Oracle database using a tool like SQLPlus. Once you are connected, you can run the query by typing it into the SQLPlus prompt.
For example, to run the query above, you would type the following into the SQL*Plus prompt:
SQL
This would return a list of all tables in the database that have the specified columns.